<?php
/**
 * Created by PhpStorm.
 * User: w
 * Date: 2016/5/16
 * Time: 14:34
 */
class Test_userController extends BaseController {
    function index(){
        //测试人员信息
        $do = new DoTest_user();
        $test_user = $do->rows();
       require  $this->template;
    }

    //测试发送文本消息
    function send_text_url() {
        $toUserID = 'olgTfw8TV4JzvN8rY9dmD_DeYHcs';
        $content = "恭喜您中奖啦！";
        $cont = '{
                "touser": "' . $toUserID . '",
                "msgtype": "text",
                "text": {
                    "content": "' . $content . '"
                }
                }';
        $url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=$this->accessToken";

        $ret = $this->curl_post_page($url,$cont);
    }
    function form_test_user(){
        $do=new DoTest_user();
        if (!empty($_POST)) {
            $openid = $this->request('openId');
            $name = $this->request("name") ;
            $id = $this->request('id');
            if(!empty($id) ){
                $do->set_id( $id);
            }
            $do->set_openId($openid);
            $do->set_name($name);
            $do->save();
            $this->redirect('test_user', 'index');
        } else {
            if(isset($_GET['id'])){
                $do->row($_GET['id']);
                $test_user_one = $do->data;
            }
            require $this->template;
        }
    }

    function del(){

        $do = new DoTest_user();
        $id = $this->request('id');
        $do->set_id($id);
        $res = $do->delete();
        $this->redirect('test_user', 'index');
    }
}